package cn.itrip.trade.service;

import cn.itrip.dao.ItripHotelOrderDao;
import cn.itrip.dao.ItripHotelTempStoreDao;
import cn.itrip.entity.ItripHotelOrder;
import cn.itrip.entity.ItripHotelTempStore;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * @author Super God Jie
 * @version 1.0  2022-04-18 15:08
 */
@Service
public class OrderService {
	@Resource
	private ItripHotelOrderDao itripHotelOrderDao;
	@Resource
	private ItripHotelTempStoreDao itripHotelTempStoreDao;

	public ItripHotelOrder aliQueryOrderInfo(String orderNo){
		return itripHotelOrderDao.aliQueryOrderInfo(orderNo);
	}

	@Transactional(rollbackFor = Exception.class)
	public void updateOrderStatusANDPayType_modifyStore(String orderNo,String tradeNo) throws Exception {
		ItripHotelOrder itripHotelOrder = itripHotelOrderDao.aliQueryOrderInfo(orderNo);
		itripHotelOrder.setOrderStatus(2);
		itripHotelOrder.setPayType(1);
		itripHotelOrder.setTradeNo(tradeNo);
		//更新订单状态
		itripHotelOrderDao.update(itripHotelOrder);
		//修改实时库存
		Map<String,Object> result = new HashMap<>();
		result.put("hotelId",itripHotelOrder.getHotelId());
		result.put("roomId",itripHotelOrder.getRoomId());
		result.put("checkInDate",itripHotelOrder.getCheckInDate());
		result.put("checkOutDate",itripHotelOrder.getCheckOutDate());
		result.put("count",itripHotelOrder.getCount());

		itripHotelTempStoreDao.updateTempStore(result);
	}

	public ItripHotelOrder queryOrderNo(String orderNo){
		Map<String,String> map = new HashMap<>();
		map.put("orderNo",orderNo);
		return itripHotelOrderDao.getPreorderInfo(map);
	}
}